package com.itboye.jigongbao.logincontroller;


import android.util.Log;

import com.itboye.jigongbao.app.MyApplication;
import com.itboye.jigongbao.bean.LoginInfo;
import com.itboye.jigongbao.utils.Const;
import com.umeng.message.UTrack;

/**
 * 登录相关控制类--状态模式</br></br>
 * <p>
 * 登录成功后调用setLoginState(new LoginedState());</br></br>
 * 退出登录后调用setLoginState(new UnLoginState());</br></br>
 * 进入主Activity前一定要设置一次，要么登录要么未登录</br></br>
 *
 * @author Mr.w
 */
public class LoginController {

    private static ILoginState loginState = new UnLoginState();

    public static void setLoginState(ILoginState loginState) {

        LoginController.loginState = loginState;

        if (loginState instanceof UnLoginState) {
            Log.d(Const.Companion.getTAG_DEBUG(), "未登录");
        } else if (loginState instanceof LoginedState) {
            Log.d(Const.Companion.getTAG_DEBUG(), "已登录。。。");
            LoginInfo login=MyApplication.Companion.getInstance().getLoginInfo();
            //添加友盟别名
            MyApplication.Companion.getInstance().getMPushAgent().addAlias(MyApplication.Companion.getInstance().getLoginInfo().getUid() + "", Const.Companion.getUMNG_ALIAS(), new UTrack.ICallBack() {
                @Override
                public void onMessage(boolean isSuccess, String message) {
                    Log.v(Const.Companion.getTAG_DEBUG(), "addAlias onMessage result = " + isSuccess + ",message=" + message);
                }
            });
        }
    }
}
